if ARGV.length < 1
  puts "Usage #{$0} effort_data_file"
  exit 1
end

numbers = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];

partnerData = Array.new
partnerTotalEffort = Array.new
wpTotalEffort = nil

input = File.new(ARGV[0])
input.each_line do |line|
  data = line.split("|")
  if data[0][0] != 35 then
    partnerData.push(data)
    partnerTotalEffort.push(0.0)
    
    if wpTotalEffort == nil then
      wpTotalEffort = Array.new(data.length - 3)
    end
  end
end

for i in 0..(wpTotalEffort.length - 1) 
  wpTotalEffort[i] = 0.0
end

for i in 0..(partnerData.length - 1)
  puts "\\newcommand\{\\partner" + numbers[i + 1] + "Name\}\{" + partnerData[i][0].strip + "\}"
  puts "\\newcommand\{\\partner" + numbers[i + 1] + "Country\}\{" + partnerData[i][1].strip + "\}"
  puts "\\newcommand\{\\partner" + numbers[i + 1] + "Code\}\{" + partnerData[i][2].strip + "\}"
  
  for j in 3..(partnerData[i].length - 1)
    puts "\\newcommand\{\\partner" + numbers[i + 1] + "EffortWP" + numbers[j - 2] + "\}\{" + partnerData[i][j].strip + "\}" 
    
    partnerTotalEffort[i] += partnerData[i][j].strip.to_f     
    wpTotalEffort[j - 3] += partnerData[i][j].strip.to_f
  end  
  
  puts
end

globalEffort = 0.0
for i in 0..(partnerTotalEffort.length - 1)
  puts "\\newcommand\{\\partner" + numbers[i + 1] + "TotalEffort\}\{" + partnerTotalEffort[i].to_s + "\}"
  globalEffort += partnerTotalEffort[i]
end

for i in 0..(wpTotalEffort.length - 1)
  puts "\\newcommand\{\\wp" + numbers[i + 1] + "TotalEffort\}\{" + wpTotalEffort[i].to_s + "\}"
end

puts "\\newcommand\{\\globalEffort\}\{" + globalEffort.to_s + "\}"